home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 287_01 / calcaddr.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-23  |  11.4 KB  |  411 lines

  1.         TITLE   CALCADDR of GDS
  2.         page    60,132
  3.         .SFCOND
  4. ;
  5. ; *==========================================================*
  6. ; *   This module contains most of the hardware dependent    *
  7. ; *   definition here. Currently only IBM color graphics     *
  8. ; *   card (640X400 mode) and Hercules graphics (720X348)    *
  9. ; *   are supported. Read MAKE.DOC for instruction on how    *
  10. ; *   to compile the program for one of them.                *
  11. ; *                                                          *
  12. ; *   If you want to use other kind of display card. You     *
  13. ; *   have to modify this file your self. More information   *
  14. ; *   on this can be found in CUSTOMIZ.DOC                   *
  15. ; *==========================================================*
  16.  
  17. IFDEF   COLOR
  18.   IFDEF HERC
  19.    .err both display type defined
  20.   ENDIF
  21. else
  22.   IFNDEF HERC
  23.     HERC equ 0
  24.   ENDIF
  25. ENDIF
  26.  
  27. smo     equ     4       ; small model offset value
  28.  
  29. IFDEF   HERC
  30.   IFDEF HERCHALF
  31. absscrn segment at 0b000h ; for Hercules page 0 of 0..1
  32.   ELSE
  33. absscrn segment at 0b800h ; for Hercules page 1 of 0..1
  34.   ENDIF
  35. ; commented out last line and uncommented next line to use page 0
  36. ; absscrn segment at 0b000h ; for Hercules page 0 of 0..1
  37. ENDIF
  38.  
  39. IFDEF   COLOR
  40. absscrn segment at 0b800h ; for Color Graphics Card
  41. ENDIF
  42.         public  _SCREEN
  43.         org     0
  44. _SCREEN label   word            ; define the address of video memory
  45. absscrn ends
  46.  
  47. ; *----------------------------------------------------------*
  48. ; * Address of 8x8 character font in IBM BIOS. This is also  *
  49. ; * true for most IBM compatibles.                           *
  50. ; *                                                          *
  51. ; * This is the font used for font number 0 in text display. *
  52. ; * if your computer don't have the font in the BIOS or      *
  53. ; * your character font is not 8X8, read CUSTOMIZ.DOC        *
  54. ; *----------------------------------------------------------*
  55. absfont segment at 0ffa6h 
  56.         public  _ROMFONT
  57.         org     0eh
  58. _ROMFONT label   byte   ; its address is F000:FA6E or FFA6:000E
  59. absfont ends
  60.  
  61. DGROUP  group   _DATA
  62. _DATA   segment word public 'DATA'
  63.         assume  ds:DGROUP
  64.         extrn   _CUR_FRAME:word
  65.         extrn   _FTABLE:word,_FRM_ST:word
  66.         extrn   _LNBYTE:word, _LADDRO:word, _LADDRS:word
  67.         extrn   _LASTX:word, _LASTY:word
  68.  
  69. IFDEF JLASER
  70.         extrn   jlaserseg:word
  71. ENDIF
  72.  
  73. IFDEF HERC
  74. gtable  db      35h,2dh,2eh,07h         ; 6845 parameter for
  75.         db      5bh,02h,57h,57h         ; Hercules graphics mode
  76.         db      02h,03h,00h,00h
  77. ttable  db      61h,50h,52h,0fh         ; 6845 parameter for
  78.         db      19h,06h,19h,19h         ; Hercules text mode
  79.         db      02h,0dh,0bh,0ch
  80. ENDIF
  81. _DATA   ends
  82.  
  83. _TEXT   segment byte public 'CODE'
  84.         assume  cs:_TEXT,ds:DGROUP
  85.         public  _calcaddr, $calc, _settext, _setgraph, downln, _phyaddr
  86.  
  87. IFDEF HERC
  88. ;
  89. ; port address
  90. ; read Hercules user manual for more information
  91. index   equ     03b4h
  92. cntrl   equ     03b8h
  93. config  equ     03bfh
  94. ; control codes
  95. scrn_on equ     8
  96. grph    equ     2
  97. text    equ     20h
  98.  
  99. IFDEF HERCHALF
  100. pagenu  equ     00h
  101. ELSE
  102. pagenu  equ     80h
  103. ENDIF
  104.  
  105. _settext proc    near    ;public to c
  106.         push    es
  107.         push    si
  108.         push    di
  109.         mov     al,0
  110.         mov     dx,config
  111.         out     dx,al
  112.         mov     al,text
  113.         lea     si,ttable
  114.         mov     bx,720h
  115.         mov     cx,2000
  116.         call    setmd
  117.         pop     di
  118.         pop     si
  119.         pop     es
  120.         ret
  121. _settext endp
  122. ;
  123. _setgraph proc   near    ;public to c
  124.         push    es
  125.         push    si
  126.         push    di
  127.         mov     al,03h
  128.         mov     dx,config
  129.         out     dx,al
  130.         mov     al,grph+pagenu
  131.         lea     si,gtable
  132.         mov     bx,0
  133.         mov     cx,4000h
  134.         call    setmd
  135.         pop     di
  136.         pop     si
  137.         pop     es
  138.         ret
  139. _setgraph endp
  140. ;
  141. setmd   proc    near
  142.         push    ds
  143.         push    es
  144.         push    ax
  145.         push    bx
  146.         push    cx
  147.         mov     dx,cntrl
  148.         out     dx,al
  149.         mov     ax,ds
  150.         mov     es,ax
  151.         mov     dx,index
  152.         mov     cx,12
  153.         xor     ah,ah
  154. parms:  mov     al,ah
  155.         out     dx,al
  156.         inc     dx
  157.         lodsb
  158.         out     dx,al
  159.         inc     ah
  160.         dec     dx
  161.         loop    parms
  162.         pop     cx
  163.         mov     ax,absscrn
  164.         cld
  165.         mov     es,ax
  166.         xor     di,di
  167.         pop     ax
  168.         rep     stosw
  169.         mov     dx,cntrl
  170.         pop     ax
  171.         add     al,scrn_on
  172.         out     dx,al
  173.         pop     es
  174.         pop     ds
  175.         ret
  176. setmd   endp
  177. ENDIF
  178.  
  179. IFDEF COLOR
  180. _settext proc   near    ; public to c
  181.         push    si
  182.         push    di
  183.         mov     ax,02
  184.         int     010h
  185.         pop     di
  186.         pop     si
  187.         ret
  188. _settext endp
  189.  
  190. _setgraph proc  near    ; public to c
  191.         push    si
  192.         push    di
  193.         mov     ax,06
  194.         int     010h
  195.         pop     di
  196.         pop     si
  197.         ret
  198. _setgraph endp
  199. ENDIF
  200.  
  201. ; *----------------------------------------------------------*
  202. ; * routine to calculate the word address of any dot in      *
  203. ; * any frame. However, it is optimize for the predefined    *
  204. ; * screen.                                                  *
  205. ; *----------------------------------------------------------*
  206. ;       x coordinate in AX
  207. ;       y coordinate in BX
  208. ;       return value in AX:BX
  209. ;       CL and DX are also affected.
  210. $calc   proc    near
  211.         push    ax
  212.         mov     ax,_CUR_FRAME   ; get current frame number
  213.         test    ax,ax           ; frame 0
  214.         jz      cal1            ; use the optimized routine
  215. IFDEF JLASER
  216.         cmp     ax,01h
  217.         jne     notjlsr
  218.         push    ds
  219.         mov     ax,jlaserseg
  220.         mov     ds,ax
  221.         shl     bx,1
  222.         mov     ax,[bx+06000h]
  223.         pop     ds
  224.         sub     bx,bx
  225.         xchg    bh,ah
  226.         shr     bx,1
  227.         shr     bx,1
  228.         pop     dx
  229.         mov     cl,4
  230.         shr     dx,cl
  231.         shl     dx,1
  232.         add     bx,dx
  233.         ret
  234. notjlsr:
  235. ENDIF
  236.         mov     ax,bx           ; otherwise use parameter in table
  237.         mul     _LNBYTE         ; line offset in dx ax
  238.         pop     bx              ; get x coordinate in bx
  239.         mov     cl,4
  240.         shr     bx,cl           
  241.         shl     bx,1            ; get horizontal offset in byte
  242.         add     bx,ax           ; add with line offset to get result
  243.         adc     dx,0      
  244.         add     bx,_FRM_ST      ; add with the frame starting address
  245.         adc     dx,0
  246.         mov     ax,bx          
  247.         mov     cx,4
  248. cal4:   shr     dx,1            ; shift right 4 to get para. number
  249.         rcr     ax,1
  250.         loop    cal4
  251.         add     ax,_FRM_ST+2    ; segment number in ax, add with start addr
  252.         sub     ax,64           ; 
  253.         and     bx,0fh          ; use last digit only
  254.         add     bx,1024         ; offset is at least 1024
  255.         ret
  256.  
  257. IFDEF COLOR
  258. ; The code below if for Color Graphics Card only
  259. cal1:   mov     ax,0
  260.         shr     bx,1
  261.         jnc     short cal3
  262.         mov     ax,0200h        ; odd lines start at ba00h segment
  263. cal3:   add     ax,absscrn      ; even lines start b800h segment
  264.         pop     dx              ; get x coordinate in dx
  265.         mov     cl,4
  266.         shr     dx,cl
  267.         shl     dx,1            ; get horizontal byte offset
  268.         mov     cl,4            ; 
  269.         shl     bx,cl           ; bx <<= 4 <==> 16*bx
  270.         add     dx,bx
  271.         shl     bx,1            ; 
  272.         shl     bx,1            ; bx <<=2  <==> 4*bx <==> 64*y
  273.                                 ; 16+64 = 80 (80 byte per line)
  274.         add     bx,dx           ; move offset in bx
  275.         ret
  276. ENDIF
  277.  
  278. IFDEF HERC
  279. ;
  280. ; The code below is for Hercules Card
  281. cal1:   mov     ax,bx           ; move y coordinate to ax
  282.         shr     ax,1            ; 
  283.         shr     ax,1            ; y coordinate / 4
  284.         mul     _LNBYTE         ; get line offset from begining of region
  285.         xchg    ax,bx           ; move y coordinate to ax again
  286.         and     ax,03h          ; get region number 0..3
  287.         mov     cl,9
  288.         shl     ax,cl           ; region number * 512 
  289.         add     ax,absscrn      ; add with starting segment number
  290.         pop     dx              ; get x coordinate in dx
  291.         mov     cl,4
  292.         shr     dx,cl
  293.         shl     dx,1            ; get horizontal offset number
  294.         add     bx,dx           ; offset in bx
  295.         ret
  296. ENDIF
  297.  
  298. $calc   endp
  299.  
  300. ; A C callable routine
  301. ;       ret=calcaddr(x,y);
  302. ;       int huge ret;
  303. ;       int x,y;
  304. ;
  305. ;       return value is a 4-byte pointer
  306. _calcaddr proc   near    ;public to c
  307.         push    bp
  308.         mov     bp,sp
  309.         mov     ax,[bp+smo]     ; get x coordinate
  310.         mov     bx,[bp+smo+2]   ; get y coordinate
  311.         call    $calc
  312.         mov     dx,ax           ; result return in DX:AX
  313.         mov     ax,bx
  314.         pop     bp
  315.         ret
  316. _calcaddr endp
  317.  
  318. _phyaddr proc   near
  319.         push    bp
  320.         mov     bp,sp
  321.         mov     ax,[bp+smo]
  322.         mov     bx,[bp+smo+2]
  323.         call    $calc
  324. IFDEF JLASER
  325.         cmp     _CUR_FRAME,01h
  326.         jne     isphy
  327.         mov     dx,0220h
  328.         out     dx,al
  329.         mov     ax,jlaserseg
  330. isphy:
  331. ENDIF
  332.         mov     dx,ax
  333.         mov     ax,bx
  334.         pop     bp
  335.         ret
  336. _phyaddr endp
  337.  
  338. ; *----------------------------------------------------------*
  339. ; * This routine is used to calculate the address of dot     *
  340. ; * below current dot. Address in given in es:bx             *
  341. ; *----------------------------------------------------------*
  342. ; input es:bx
  343. ; output es:bx
  344. ; also affect si and use the global variable _LASTY
  345. downln  proc    near
  346.         mov     si,_CUR_FRAME
  347.         test    si,si
  348.         jz      dl01            ; not frame 0
  349. IFDEF JLASER
  350.         cmp     si,01h
  351.         jne     dlother
  352.         push    ax
  353.         mov     si,_LASTY
  354.         shl     si,1
  355.         mov     ax,jlaserseg
  356.         mov     es,ax
  357.         mov     ax,es:[si+06000h]
  358.         sub     al,al
  359.         shr     ax,1
  360.         shr     ax,1
  361.         sub     bx,ax
  362.         inc     _LASTY
  363.         add     si,2
  364.         mov     ax,es:[si+06000h]
  365.         mov     si,ax
  366.         sub     ah,ah
  367.         mov     es,ax
  368.         mov     ax,si
  369.         sub     al,al
  370.         shr     ax,1
  371.         shr     ax,1
  372.         add     bx,ax
  373.         pop     ax
  374.         ret
  375. dlother:
  376. ENDIF
  377.         mov     si,es           ; for frame created by GDS
  378.         add     si,_LADDRS      ; next line is always _LADDRS:_LADDRO
  379.         mov     es,si           ; from current line
  380.         add     bx,_LADDRO
  381.         ret
  382.  
  383. IFDEF HERC
  384. dl01:   mov     si,es
  385.         inc     word ptr _LASTY
  386.         test    _LASTY,03h      ; get current region number
  387.         jnz     dl02            ; then update address appropiately
  388.         sub     si,0800h
  389.         add     bx,90
  390. dl02:   add     si,0200h
  391.         mov     es,si
  392.         ret
  393. ENDIF
  394.  
  395. IFDEF COLOR
  396. dl01:   mov     si,es
  397.         inc     word ptr _LASTY
  398.         test    _LASTY,01h
  399.         jnz     dl02
  400.         sub     si,0400h
  401.         add     bx,80
  402. dl02:   add     si,0200h
  403.         mov     es,si
  404.         ret
  405. ENDIF
  406. downln  endp
  407.  
  408. _TEXT   ends
  409.         end
  410.  
  411.